home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / nvdc87 / extrac / mymenu.pro < prev    next >
Text File  |  1987-07-28  |  4KB  |  132 lines

  1. /************************************************************
  2.         Listing 1.
  3.         Turbo Prolog Toolbox Article
  4.  
  5.     This program demonstrates the use of extracted
  6.     predicates from files furnished on the Turbo Prolog
  7.     Toolbox distribution disks.  It creates two new
  8.     INCLUDE files from those on the distribution disks:
  9.     MENPREDS.PRO from TPREDS.PRO and NEWMENU.PRO from
  10.     MENU.PRO.  In both cases, unneeded predicates have
  11.     been removed from the original files and the modified
  12.     files saved separately.
  13. ************************************************************/
  14. include "tdoms.pro"     /* no modifications - nothing to delete */
  15. include "menpreds.pro"  /* as modified for this program         */
  16. include "newmenu.pro"   /* as modified for this program         */
  17.  
  18. predicates
  19.     member(integer,integerlist)
  20.     fun(integerlist)
  21.     power_user(integerlist)
  22.     developer(integerlist)
  23.     fun_only(integerlist)
  24.     all_work(integerlist)
  25.     crazy(integerlist)
  26.     write_it(integerlist)
  27. goal
  28.  
  29.     clearwindow,
  30.     menu_mult(10,10,7,7,["Arcade-style games","Databases",
  31.         "Expert Systems Development","Math Research",
  32.         "Programming","Spreadsheets","Telecommunications",
  33.         "Text Adventure    Games","Word Processing"],
  34.         "Select all of the things for which you use a 
  35.          computer",
  36.         [],Choices),
  37.     write_it(Choices).
  38.     
  39. clauses
  40.  
  41. /* These predicates permit us to categorize responses from the
  42. menu in such a way as to make the computer's analysis and advice
  43. more interesting and less expected.  To see what they are intended
  44. to mean, look at the "write_it" clauses below.  All work basically
  45. the same way.  The menu choices are categorized into "fun", "power
  46. user", "developer" and "crazy."  Since the user is making a
  47. multiple-choice selection, his/her replies are stored in a list
  48. called Choices (as set up in the "menu_mult" predicate call in
  49. the goal, above).  Then we just use the "member" predicate to
  50. determine if a particular value is part of that list or not. */
  51.  
  52.     fun(Choices) :-
  53.         member(1,Choices).
  54.         
  55.     fun(Choices) :-
  56.         member(8,Choices).
  57.     
  58.     power_user(Choices) :-
  59.         member(2,Choices).
  60.         
  61.     power_user(Choices) :-
  62.         member(6,Choices).
  63.         
  64.     power_user(Choices) :-
  65.         member(7,Choices).
  66.         
  67.     power_user(Choices) :-
  68.         member(9,Choices).
  69.         
  70.     developer(Choices) :-
  71.         member(3,Choices).
  72.         
  73.     developer(Choices) :-
  74.         member(5,Choices).
  75.         
  76.     crazy(Choices) :-
  77.         member(4,Choices). /* Isn't any math researcher? */
  78.         
  79. /* If the user indicates only game choices, s/he's categorized as
  80.    "fun_only" for our purposes. */
  81.  
  82.     fun_only(Choices) :-
  83.         fun(Choices),
  84.         not(power_user(Choices)),
  85.         not(developer(Choices)).
  86.         
  87. /* Similarly, if the user indicates no fun choices at all, but only
  88.    power user or programmer uses, s/he's categorized as 
  89.    "all_work". */
  90.  
  91.     all_work(Choices) :-
  92.         not(fun(Choices)),
  93.         power_user(Choices).
  94.         
  95.     all_work(Choices) :-
  96.         not(fun(Choices)),
  97.         developer(Choices).
  98.         
  99.     all_work(Choices) :-
  100.         not(fun(Choices)),
  101.         not(crazy(Choices)).
  102.  
  103. /* Here come the messages of advice -- words of wisdom, if you will --
  104.    for each category of respondent. */
  105.  
  106.     write_it(Choices) :-
  107.         fun_only(Choices),
  108.         write("Maybe it's time you got serious about your 
  109.                computer!").
  110.         
  111.     write_it(Choices) :-
  112.         all_work(Choices),
  113.         write("All work and no play makes for rich, but dull, 
  114.                programmers!").
  115.         
  116.     write_it(Choices) :-
  117.         crazy(Choices),
  118.         write("You are definitely a strange duck!").
  119.         
  120.     write_it(Choices) :-
  121.         not(fun_only(Choices)),
  122.         not(all_work(Choices)),
  123.         not(crazy(Choices)),
  124.         write("You seem to be pretty well-balanced.").
  125.         
  126. /* Standard "member" definition, but not included with Turbo 
  127.    Prolog. */
  128.  
  129.     member(X,[X|_]).
  130.     member(X,[_|Y]) :-
  131.         member(X,Y).
  132.